<template>
	<view>
		<view class="wrap">
			<view class="">
				<u-dropdown ref="uDropdown">
					<u-dropdown-item :title="title1" :options="options1" v-model="selCla" @change="changeCLass($event)">
					</u-dropdown-item>
				</u-dropdown>
			</view>
			<uni-calendar :clearDate="true" :showMonth="false" :insert="true" :selected="selected" :lunar="false"
				:start-date="'1990-01-01'" :end-date="'2099-01-01'" @monthSwitch="monthSwitch" @change="dateChange">
			</uni-calendar>

			<view v-if="dataList.length>0">
				<uni-card :title="item.title" :extra="item.addrs" v-for="(item,index) in dataList" :key="index"
					@click="createQrCode(item)">
					<text class="uni-body" v-html="item.content" style="line-height: 60px;"></text>
					<uni-list>
						<uni-list-item :title="item.attendClassTime"></uni-list-item>
						<uni-list-item :title="item.quittingTime"></uni-list-item>
					</uni-list>
					<view style="text-align: right;">点击生成签到二维码</view>
				</uni-card>
			</view>
			<view v-else>
				<view style="text-align: center;justify-content: center;align-content: center;">
					<u-empty text="" mode="data"></u-empty>
				</view>

			</view>

		</view>

	</view>
</template>

<script>
	import {
		getTeacherCourseListByClassId,
		delByid,
		getClassInfoByTeacherId
	} from '@/api/jz/course/api.js'
	export default {
		data() {
			return {
				selected: [],
				content: "确认删除吗?",
				dataList: [

				],
				dataList2 :[],
				options1: [],
				title1: "班级",
				selCla: "",
				show: false,
				show2: false,
				list: [{
						name: '待付款'
					},
					{
						name: '待发货'
					},
					{
						name: '待收货'
					},
					{
						name: '待评价',
						count: 12
					}
				],
				pointList: [],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['loadmore', 'loadmore', 'loadmore', 'loadmore'],
				courseId: "",
				defaultDate: null,
				index: null
			};
		},
		onLoad() {

		},
		mounted() {
			var date = new Date();
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			var d = date.getDate();
			this.defaultDate = y + "-" + m + "-" + d;

			this.getClassInfoByTeacherId();

		},
		computed: {

		},
		methods: {
			/**
			 * 选中日期的触发事件
			 */
			dateChange: function(e) {
				console.log(e);
				var arr=[];
				for (var i = 0; i < this.dataList2.length; i++) {
					if (this.dataList2[i].date == e.fulldate) {
                           arr.push(this.dataList2[i])
					}
				}
				this.dataList = arr;
			},
			/**
			 *  选中月份的触发事件
			 */
			monthSwitch: function(e) {
				console.log(e);
			},

			formatTime(str) {
				console.log(str)
				var y = new Date(str).getFullYear();
				var m = new Date(str).getMonth() + 1;
				if (m < 10) {
					m = "0" + m;
				}
				var d = new Date(str).getDate();
				if (d < 10) {
					d = "0" + d;
				}
				return y + '-' + m + '-' + d;
			},
			createQrCode(val) {
				const params = encodeURIComponent(JSON.stringify(val))
				this.$tab.navigateTo("/pages/work/qrCode/index/index?data=" + params)
			},
			async getClassInfoByTeacherId() {
				this.options1 = []
				let res = await getClassInfoByTeacherId();
				for (var i = 0; i < res.length; i++) {
					this.options1.push({
						label: res[i].className,
						value: res[i].id
					})
					this.title1 = this.options1[0].label
					this.selCla = this.options1[0].value
					this.getList();
				}

			},
			async getList(id) {
				let data = {
					type: 1,
					classId: this.selCla

				}
				await getTeacherCourseListByClassId(data).then((res) => {
					if (res.code == 200) {
						for (var i = 0; i < res.rows.length; i++) {
							res.rows[i].date = this.formatTime(res.rows[i].attendClassTime)
							res.rows[i].type = "abnormal";
							res.rows[i].attendClassTime = "上课时间：" + res.rows[i].attendClassTime;
							res.rows[i].quittingTime = "下课时间：" + res.rows[i].quittingTime;
							if (res.rows[i].professorName) {
								res.rows[i].title = res.rows[i].title + "(" + res.rows[i].professorName + ")"
							}

						}
						this.dataList = res.rows;
						this.dataList2 = this.dataList
						this.selected = res.rows;
					}
				})


			},
			del(row) {
				this.courseId = row.id
				this.show = true;
			},

			confirm() {
				delByid(this.courseId).then((res) => {
					if (res.code == 200) {
						this.getList();
					}
				})
			},



			async changeDate(e) {
				if (e.month < 10) {
					e.month = "0" + e.month
				}
				if (e.dayday < 10) {
					e.day = "0" + e.day
				}
				let data = {
					type: 2,
					classId: this.selCla,
					attendClassTime: e.year + "-" + e.month + "-" + e.day + " 00:00:00"
				}

				await getTeacherCourseListByClassId(data).then((res) => {
					if (res.code == 200) {
						for (var i = 0; i < res.rows.length; i++) {
							res.rows[i].attendClassTime = "上课时间：" + res.rows[i].attendClassTime;
							res.rows[i].quittingTime = "下课时间：" + res.rows[i].quittingTime;
							if (res.rows[i].professorName) {
								res.rows[i].title = res.rows[i].title + "(" + res.rows[i].professorName + ")"
							}

						}
						this.dataList = res.rows;
					}
				})

			},
			changeCLass(val) {
				for (var i = 0; i < this.options1.length; i++) {
					if (this.options1[i].value == val) {
						this.title1 = this.options1[i].label
						break;
					}
				}
				this.getList()
			},

			// tab栏切换
			change(index) {
				this.swiperCurrent = index;
				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			}
		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>

</style>